<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['params']=array('type'=>1);
	set_html('title','分红明细');
	exi($return);
}
if($_RQ['op']=='list'){
	$member=$this->get('agent',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$params=array('uniacid'=>$_SESSION['uniacid'],'dian_id'=>$member['id']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=$this->pdo_getslice('commission',$params,array($pindex,$psize),$total,'','','id desc');
	if($list){
		foreach($list as &$item){
			$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'id');
			$ordergoods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$orderid,'uniacid'=>$_SESSION['uniacid']),array('goodsid','istaocan','optionid','price','total','goodssn','productsn'));
			foreach($ordergoods as &$gv){
				$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice','unit','image','title','merchid'));
				$goodsinfo['total']=$gv['total'];
				$goodsinfo['price']=$gv['price'];
				if($_SESSION['is_tomedia']){
					$goodsinfo['image']=$goodsinfo['image']?tomedia($goodsinfo['image']):'';
				}
				$goodsinfo['weight']=pdo_getcolumn('jy_weishop_goods_dispatch',array('goodsid'=>$gv['goodsid']),'weight');
				//商品规格
				if($gv['optionid']){
					$options=pdo_get('jy_weishop_goods_option',array('id'=>$gv['optionid']),array('title','specs'));
					if($gv['istaocan']){
						$goodsinfo['selespename']=$options['title'];
					}else{
						$specs=$options['specs'];
						$specs=explode("_",$specs);
						foreach($specs as &$spec){
							$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
						}
						$goodsinfo['selespename']=implode("，",$specs);
					}
				}
				$item['goods'][] = $goodsinfo;
			}
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['statustitle']=$this->commission_status[$item['status']];
		}
	}
	$return['list']=$list;
	exi($return);
}